package com.ruoyi.process.ccs.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.process.ccs.domain.CcsHiddenTrouble;
import com.ruoyi.process.ccs.service.ICcsHiddenTroubleService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 隐患信息记录Controller
 *
 * @author Xianlu Tech
 * @date 2020-04-02
 */
@Controller
@RequestMapping("/process/trouble")
public class CcsHiddenTroubleController extends BaseController {
    private String prefix = "process/trouble";

    @Autowired
    private ICcsHiddenTroubleService ccsHiddenTroubleService;

    @RequiresPermissions("process:trouble:view")
    @GetMapping()
    public String trouble() {
        return prefix + "/trouble";
    }

    /**
     * 查询隐患信息记录列表
     */
    @RequiresPermissions("process:trouble:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CcsHiddenTrouble ccsHiddenTrouble) {
        startPage();
        List<CcsHiddenTrouble> list = ccsHiddenTroubleService.selectCcsHiddenTroubleList(ccsHiddenTrouble);
        return getDataTable(list);
    }

    /**
     * 导出隐患信息记录列表
     */
    @RequiresPermissions("process:trouble:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CcsHiddenTrouble ccsHiddenTrouble) {
        List<CcsHiddenTrouble> list = ccsHiddenTroubleService.selectCcsHiddenTroubleList(ccsHiddenTrouble);
        ExcelUtil<CcsHiddenTrouble> util = new ExcelUtil<CcsHiddenTrouble>(CcsHiddenTrouble.class);
        return util.exportExcel(list, "trouble");
    }

    /**
     * 新增隐患信息记录
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存隐患信息记录
     */
    @RequiresPermissions("process:trouble:add")
    @Log(title = "隐患信息记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CcsHiddenTrouble ccsHiddenTrouble) {
        return toAjax(ccsHiddenTroubleService.insertCcsHiddenTrouble(ccsHiddenTrouble));
    }

    /**
     * 修改隐患信息记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        CcsHiddenTrouble ccsHiddenTrouble = ccsHiddenTroubleService.selectCcsHiddenTroubleById(id);
        mmap.put("ccsHiddenTrouble", ccsHiddenTrouble);
        return prefix + "/edit";
    }

    /**
     * 修改保存隐患信息记录
     */
    @RequiresPermissions("process:trouble:edit")
    @Log(title = "隐患信息记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CcsHiddenTrouble ccsHiddenTrouble) {
        return toAjax(ccsHiddenTroubleService.updateCcsHiddenTrouble(ccsHiddenTrouble));
    }

    /**
     * 删除隐患信息记录
     */
    @RequiresPermissions("process:trouble:remove")
    @Log(title = "隐患信息记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(ccsHiddenTroubleService.deleteCcsHiddenTroubleByIds(ids));
    }
}
